package com.yz.test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

//想文件中写入数据
public class WriterData {
    public static void main(String[] args) throws FileNotFoundException {
        File file = new File("score.txt");

        //先判断文件是否存在
        if (file.exists()){
            System.out.println("该文件已存在！");
            System.exit(0);
        }
        //创建这个PrintWrite这个类来写入数据到文件
        PrintWriter writer = new PrintWriter(file);
        writer.print("Json T Smith ");
        writer.println(100);

        writer.print("Eric K Jones");
        writer.println(90);

        //将数据写入到这个文件之后，将写操作关闭
        writer.close();

    }
}
